﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <title>易得桌面</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageStyles" runat="server">
    <style type="text/css">
        
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageScripts" runat="server">
    <link href="../../Content/userInfoSelect.css" rel="stylesheet" type="text/css" />
    <script src="../../Content/xheditor/xheditor-zh-cn.js" type="text/javascript"></script>
    <script type="text/javascript">

        //************* URL常量

        var URL_MESSAGE_SEND = '/Message/DoSend';

        //************* 全局变量

        var g_Var = {
            'currentTime': null,
            'currentUser': null,
            'recieverId': 'everyone'

        };

        //************* 常量定义

        //************* Accessor访问器

        var EzAccessor = {};

        if (ezmock.IS_MOCKED) {
            var mock_currentTime = { "CurrentTime": 1348423559 };
            var mock_currentUser =
            {
                "Id": "22222",
                "Name": "李7",
                "UserName": "yuxin",
                "Dept":
                 {
                     "Id": "bd3474a8-6c2d-43ef-bf42-b06827a216f6",
                     "DeptName": "软件工程",
                     "GroupId": "9ad96dac-88d8-4315-bfdb-9931c8f3cb7c"
                 }

            };

            var mockEzAccessor = {

                'doSendMessage': function () {
                    var StatusInfo = { "Status": "Success", "Info": "发送成功！", "Data": null };
                    $.displayStatusInfo(StatusInfo);

                }
            };


            EzAccessor = mockEzAccessor;

        } else {
            var realEzAccessor = {

                'doSendMessage': function () {
                    //获得标题
                    var title = $('#messageTitle').val();

                    //获得内容
                    var text = $('#messageContent').val();

                    //获得是否需要确认
                    var needConfirm = false;
                    if ($('#isNeedToAffirm').attr("checked") == true) {
                        needConfirm = true;
                    }

                    //获得收件人名单
                    var memberString = g_Var['recieverId'];

                    //发送消息
                    $('.page-submit').ajaxBusyProgress();

                    $.post(URL_MESSAGE_SEND,
                {
                    'memberString': memberString,
                    'messageTitle': title,
                    'messageText': text,
                    'needConfirm': needConfirm
                }, function (e) {
                    if (e.Status == "Success") {
                        var url = '/message/show?topicId={topicId}';
                        url = url.replace("{topicId}", e.Data.topicId);
                        $.redirectAndDisplayInfo(url, e);
                    } else {
                        $('.page-submit').ajaxBusyProgress('reset');
                    }
                });

                }
            };

            EzAccessor = realEzAccessor;
        }

        function chooseMembersCallBack(selectedMembers) {
            // 将选中的用户加入收信人列表
            var members = [];
            var Namelist = "";

            var IdArray = [];

            $(selectedMembers)
            .each(function (index, item) {
                members[members.length] = item.Name;
                Namelist += "<p> " + item.Name + " </p> ";
                IdArray[IdArray.length] = item.Id;

            });

            g_Var['recieverId'] = IdArray.join(',');
            if (g_Var['recieverId'].length == 0) {
                g_Var['recieverId'] = "everyone";

                $('#receiver').html("所有人");
            }
            else {
                $('#receiver').html(Namelist)
            }

        }



        function checkForm() {
            // 判断标题长度
            if ($("#messageTitle").val().length > 30) {
                var StatusInfo = { 'Status': 'Error', 'Info': '消息标题太长了，要求小于30个字符！', 'Data': null };
                $.displayStatusInfo(StatusInfo);
                return false;
            }

            //判断回复是否为空
            if ($("#messageContent").val().length == 0) {
                var StatusInfo = { 'Status': 'Error', 'Info': '消息内容不能为空!', 'Data': null };
                $.displayStatusInfo(StatusInfo);
                return false;
            }
            return true;
        }


        function initPageEvent() {
            var addresseeSelector = new EzUserInfoSelector(chooseMembersCallBack);
            addresseeSelector.initialize();

            // 选择收信人点击事件
            $('#btnChooseAddressee').click(function () {
                addresseeSelector.Show();
            });

            // 创建发送消息按钮的点击事件
            $('#btnSubmit').click(function () {
                var messageConfirm = checkForm();
                if (messageConfirm) {
                    EzAccessor.doSendMessage();
                }
            });

            //选择所有人接收
            $('#btnEveryOne').click(function () {
                chooseMembersCallBack(null);
            });

            //重设
            $('#btnRecover').click(function () {
                //清空标题和内容
                $('#messageTitle').clearFields();
                $('#messageContent').val("");
                //重设memberSelcet
                chooseMembersCallBack(null);
                //取消选中的消息需要确认
                $('#isNeedToAffirm').attr('checked', '');
                EzTipsManager.hideTipBox('tipNeedConfirm');
                //隐藏标题
                $('#deleTtiel').parent().hide();
                $('#addTitel').show();
            });


            //增添标题
            $('#addTitel').click(function () {
                $(this).next().show();
                $(this).hide();
            });
            //取消标题
            $('#deleTtiel').click(function () {
                $(this).parent().hide();
                $('#addTitel').show();
                $('#messageTitle').empty();

            });

            $('#lblChecked').click(function () {
                if ($('#isNeedToAffirm').attr("checked") == true) {
                    EzTipsManager.showTipBox('tipNeedConfirm');
                } else {
                    EzTipsManager.hideTipBox('tipNeedConfirm');
                }
            });


        }



        function initPage() {
            $('#messageContent').xheditor({ tools: 'Fontface,FontSize,Bold,Italic,Underline,FontColor,BackColor,Align,Emot' });

            EzTipsManager.addTipBox('#tip_Receiver', 'tipReceiver');
            EzTipsManager.addTipBox('#tip_NeedConfirmOrNot', 'tipNeedConfirmOrNot');
            EzTipsManager.addTipBox('#tip_NeedConfirm', 'tipNeedConfirm');


            EzTipsManager.showTipBox('tipReceiver');
            EzTipsManager.showTipBox('tipNeedConfirmOrNot');
            //默认发给所有人
            $('#chkEveryOne').attr('checked', true);
            $('#chkEveryOne').attr('disabled', true);

            $('#messageContent').focus();

        }


        $(function () {
            initPage();
            initPageEvent();


        });

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PageHead" runat="server">
    <%
        Html.RenderPartial("_sayHello"); %> 
    <div id="status-bar"><% Html.RenderPartial("_navigateTo"); %><a href="/message/inbox" class="head">回到收件箱</a></div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageContent" runat="server">
    <div id="page-head">
        <img src="../../Content/icons/message_send.png" style="width: 48px; height: 48px;"
            alt="send" />
        <span>发送新消息</span>
    </div>
    <div id="page-body">
        <div class="formBox">
            <a id="addTitel">添加标题</a>
            <div style="display: none;">
                标题
                <input type="text" id="messageTitle" style="width: 300px;" />
                <a id="deleTtiel">取消标题</a>
            </div>
            <div id="text" class="r">
                <textarea id="messageContent" style="width: 100%; height: 200px;"></textarea>
            </div>
        </div>
    </div>
    <div class="page-submit">
        <input id="btnSubmit" type="submit" value="发送" />
        &nbsp;或者&nbsp;<a id="btnRecover">重置</a>
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="PageShortcut" runat="server">

</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="PageFoot" runat="server">
    <div id="tip_Receiver" style="display: none;">
        <h1>
            该消息发送给: <span style="float: right;">&nbsp;<a id="btnChooseAddressee" href="#">选择收件人</a>
                <a id="btnEveryOne">所有人</a></span>
        </h1>
        <p id="receiver" class="indent">
            所有人
        </p>
    </div>
    <div id="tip_NeedConfirmOrNot" style="display: none;">
        <h1>
            消息是否需要被确认？
            <label id="lblChecked" for="isNeedToAffirm">
                <input type="checkbox" id="isNeedToAffirm" />需要</label></h1>
    </div>
    <div id="tip_NeedConfirm" style="display: none;" class="tip-info">
        <h1>
            该消息需要被确认！</h1>
    </div>
</asp:Content>
